<?php

namespace app\controllers\web;

use Yii;
use app\models\web\LoginForm;
use yii\web\Controller;

class LoginController extends Controller{

    public function actionLogin() {
        if (!\Yii::$app->user->isGuest) {
            return $this->goHome(); // 默认 index/index
        }

        $model = new LoginForm();
        if (Yii::$app->request->isPost) {

            if ($model->load(Yii::$app->request->post()) && $model->login()) {
                return '登陆成功';
            } else {
                return '登陆失败';
            }
        } else {
            return $this->render('login', [
                'model' => $model,
            ]);
        }
    }

}